﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Guide
{
    public partial class Select1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var listProvince = (List<Province>)Session["listprovince"];
                //this.GridView1.DataSource = listProvince;
                var listClusterID = listProvince.Select(o => o.ClusterID).Distinct().ToList();
                List<Cluster> listCluster = new List<Cluster>();

                foreach (var item in listClusterID)
                {
                    listCluster.Add(new Cluster()
                        {
                            ClusterName = item,
                            ProvinceNum = listProvince.Count(o => o.ClusterID == item)
                        });
                }

                this.GridView2.DataSource = listCluster;


                var listcluster = listProvince.Select(x => new { x.ClusterID, ClusterCount = x.ProvinceID.Count() }).ToList();//.Distinct().ToList();//.ToList().Distinct().ToList();

                //from item in listProvince
                //            select new {}


                //this.GridView1.DataBind();
                this.GridView2.DataBind();

                //var cluster=from 
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            List<string> listCluserName = new List<string>();
            foreach (GridViewRow row in this.GridView2.Rows)
            {

                bool isChecked = false;
                if ((row.FindControl("CheckBox1") as CheckBox).Checked == true)
                {
                    isChecked = true;
                }
                else
                {
                    isChecked = false;
                }

                if (isChecked)
                {
                    listCluserName.Add((row.FindControl("ClusterName") as Label).Text);
                }
            }
            var x = listCluserName;
            Session["listSelectClusterName"] = listCluserName;
            Response.Redirect("/Select2.aspx");
        }
    }
}